package controllers

import (
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/sessions"
)

var (
	cookieNameForSessionID = "mycookiesessionnameid"
	sess                   = sessions.New(sessions.Config{Cookie: cookieNameForSessionID})
)

func SetUser(userid int, roleid int, name string, ctx iris.Context) {
	session := sess.Start(ctx)
	session.Set("userid", userid)
	session.Set("roleid", roleid)
	session.Set("name", name)
}

func GetUser(ctx iris.Context) (userid int, roleid int, name string, err error) {
	session := sess.Start(ctx)
	userid, err = session.GetInt("userid")
	roleid, err = session.GetInt("roleid")
	name = session.GetString("name")
	return
}
func GetUserId(ctx iris.Context) (userid int) {
	session := sess.Start(ctx)
	userid, _ = session.GetInt("userid")
	return
}
func Clean(ctx iris.Context) {
	session := sess.Start(ctx)
	session.Delete("userid")
	session.Delete("roleid")
	session.Delete("name")
}
